package br.com.skytef.beans.WEB;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

import org.primefaces.context.RequestContext;
import org.primefaces.event.SelectEvent;

import br.com.skytef.dao.PrintDao;
import br.com.skytef.entity.PrintQueueEntity;
import br.com.skytef.entity.ProductMerchandiseEntity;

@ManagedBean(name="PrintQueueBean")
@RequestScoped
public class PrintQueueBean {
	
	private List<PrintQueueEntity> listaFilaImpressao;
	
	public List<PrintQueueEntity> getListaFilaImpressao() {
		return listaFilaImpressao;
	}

	public void setListaFilaImpressao(List<PrintQueueEntity> listaFilaImpressao) {
		this.listaFilaImpressao = listaFilaImpressao;
	}
	
	public PrintQueueBean() throws IOException {
		super();
	}
	
	public void listarFila() throws Exception {
		listaFilaImpressao = new PrintDao().mostraFila();
	}

	@PostConstruct
	public void init() throws Exception {
		listaFilaImpressao = new PrintDao().mostraFila();
	}
	
	private Date date1;
	private Date date10;
	private Date date11;
	private List<ProductMerchandiseEntity> prods;

//	public void init() {
//		ProductMerchandiseEntity prod = new ProductMerchandiseEntity();
//		prods = new ArrayList<ProductMerchandiseEntity>();
//
//		prod = new ProductMerchandiseEntity();
//		prod.setId(1);
//		prod.setDescrMerchandise("Teste 1");
//		prod.setSupplDescription("Teste Sub 1");
//		prods.add(prod);
//
//		prod = new ProductMerchandiseEntity();
//		prod.setId(2);
//		prod.setDescrMerchandise("Teste 2");
//		prod.setSupplDescription("Teste Sub 2");
//		prods.add(prod);
//
//		prod = new ProductMerchandiseEntity();
//		prod.setId(2);
//		prod.setDescrMerchandise("Teste 3");
//		prod.setSupplDescription("Teste Sub 3");
//		prods.add(prod);
//
//		prod = new ProductMerchandiseEntity();
//		prod.setId(4);
//		prod.setDescrMerchandise("Teste 4");
//		prod.setSupplDescription("Teste Sub 4");
//		prods.add(prod);
//	}

	public List<ProductMerchandiseEntity> getCars() {
		return prods;
	}

	public void onDateSelect(SelectEvent event) {
		FacesContext facesContext = FacesContext.getCurrentInstance();
		SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
		facesContext.addMessage(null,
				new FacesMessage(FacesMessage.SEVERITY_INFO,
						"Data Selecionada", format.format(event.getObject())));
	}
	
	public void consultarUsuario() throws Exception{
		ProductMerchandiseEntity prod = new ProductMerchandiseEntity();
					
		prods = new ArrayList<ProductMerchandiseEntity>();

		for (int i = 0; i < 100; i++) {
			
			prod = new ProductMerchandiseEntity();
			prod.setId(i+1);
			prod.setCodeAssist("00000" + prod.getId());
			prod.setDateAmendment(new Date());
			prod.setDescrMerchandise("Teste" + prod.getId());
			prod.setSupplDescription("Teste Sub" + prod.getId());
			prod.setProductId(i+1);
			
			prods.add(prod);
		}
		
	}

	public void click() {
		RequestContext requestContext = RequestContext.getCurrentInstance();

		requestContext.update("form:display");
		requestContext.execute("PF('dlg').show()");
	}

	public Date getDate1() {
		return date1;
	}

	public void setDate1(Date date1) {
		this.date1 = date1;
	}

	public Date getDate10() {
		return date10;
	}

	public void setDate10(Date date10) {
		this.date10 = date10;
	}

	public Date getDate11() {
		return date11;
	}

	public void setDate11(Date date11) {
		this.date11 = date11;
	}

	public List<ProductMerchandiseEntity> getProds() {
		return prods;
	}

	public void setProds(List<ProductMerchandiseEntity> prods) {
		this.prods = prods;
	}

}